package com.oreilly.ez.account;

import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import org.apache.commons.io.FileUtils;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;

public class MoshiClient {


    public static void main(String[] args) throws Exception {


        File file = ResourceUtils.getFile("classpath:blackjackHand.json");
        String json = FileUtils.readFileToString(file);
        System.out.println(json);

        Moshi moshi = new Moshi.Builder().build();
        JsonAdapter<BlackjackHand> adapter = moshi.adapter(BlackjackHand.class);
        BlackjackHand blackjackHand = adapter.fromJson(json);

        System.out.println(blackjackHand);

//        System.out.println(adapter.toJson(blackjackHand));



        // 使用 CardAdapter, 解析 card
        Moshi build = new Moshi.Builder().add(new CardAdapter()).build();
        JsonAdapter<BlackjackHand> jsonAdapter = build.adapter(BlackjackHand.class);
        System.out.println(jsonAdapter.toJson(blackjackHand));
    }
}
